home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 October: Mac OS SDK / Dev.CD Oct 00 SDK1.toast / Development Kits / Mac OS / AIAT / Headers / Analysis / IACharStream.h < prev    next >
Encoding:
Text File  |  1998-04-16  |  2.2 KB  |  78 lines  |  [TEXT/CWIE]

  1. // IACharStream.h
  2. //    Copyright:    © 1994 - 1998 by Apple Computer, Inc., all rights reserved.
  3.  
  4. #pragma once
  5. #ifndef IACharStream_h
  6. #define IACharStream_h
  7. #pragma import on
  8.  
  9. #if PRAGMA_STRUCT_ALIGN
  10.     #pragma options align=power
  11. #endif
  12.  
  13. #include "IACommon.h"
  14.  
  15. #pragma IA_BEGIN_EXPORTS
  16.  
  17. class IACharStream : public IAObject {
  18. public:
  19.                     IACharStream();
  20.     virtual            ~IACharStream();
  21.     // common operations are handled inline by base class
  22.  
  23.     // note: eos is assumed to be false, and is only set when eos is reached
  24.     // also, when eos is set, the return value should be ignored
  25.     char            GetNextChar(bool* eos) { 
  26.                         return nextChar < endChar ? *(nextChar++) : ReadPastEndOfBuffer(eos);
  27.                     }
  28.  
  29.     inline uint32    CurrentPos() { return bufferPos + (nextChar - buffer); }
  30.     
  31.     void            GetTextSpan(char* buffer, uint32 startPos, uint32 endPos);
  32.  
  33.     // subclasses may wish to implement a faster version of this
  34.     virtual void    AdvanceTo(uint32 pos);
  35.     
  36.     // accessors needed for string-based subclasses
  37.     char*            GetBuffer() const { return buffer; } // returns current buffer
  38.     void            SetBuffer(char* newValue) { buffer = newValue; } // sets current buffer
  39.     
  40.     char*            GetNextCharInBuffer() const { return nextChar; }
  41.     void            SetNextCharInBuffer(char* newValue) { nextChar = newValue; }
  42.     
  43.     char*            GetEndChar() const { return endChar; }
  44.     void            SetEndChar(char* newValue) { endChar = newValue; }
  45.     
  46.     uint32            GetBufferPos() const { return bufferPos; }
  47.     void            SetBufferPos(uint32 newValue) { bufferPos = newValue; }
  48.     
  49. protected:
  50.     // subclasses must implement only this one method
  51.     virtual uint32    GetNextBuffer(char* buffer, uint32 bufferLen) = 0;
  52.     
  53. private:
  54.     char            ReadPastEndOfBuffer(bool *eos);
  55.     char*            lastBuffer;                    // the previous buffer
  56.     char*            lastEndChar;                // the end of the previous buffer
  57.  
  58.                     IACharStream(IACharStream&);// don't define a copy constructor
  59.                     
  60.     char*            buffer;                        // the current buffer
  61.     char*            nextChar;                    // pointer to the next character to read in buffer
  62.     char*            endChar;                    // pointer to the end of the current buffer            
  63.     uint32            bufferPos;                    // position of the first char in buffer
  64.  
  65. };
  66.  
  67. IAExceptionCode            TextSpanUnavailable = 'VTSU';
  68.  
  69. #pragma IA_END_EXPORTS
  70.  
  71. #if PRAGMA_STRUCT_ALIGN
  72.     #pragma options align=reset
  73. #endif
  74.  
  75. #pragma import reset
  76.  
  77. #endif
  78.